import%20marimo%0A%0A__generated_with%20%3D%20%220.17.6%22%0Aapp%20%3D%20marimo.App(width%3D%22medium%22%2C%20auto_download%3D%5B%22html%22%2C%20%22ipynb%22%5D)%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_()%3A%0A%20%20%20%20import%20pytz%0A%20%20%20%20import%20datetime%0A%20%20%20%20import%20marimo%20as%20mo%0A%0A%20%20%20%20india_timezone%20%3D%20pytz.timezone(%22Asia%2FKolkata%22)%0A%20%20%20%20now%20%3D%20datetime.datetime.now(india_timezone)%0A%0A%20%20%20%20curr%20%3D%20now.strftime(%22%25Y-%25m-%25d%2C%20%25I%3A%25M%3A%25S%20%25p%20%25Z%22)%0A%0A%20%20%20%20mo.md(%0A%20%20%20%20%20%20%20%20rf%22%22%22%0A%20%20%20%20%23%20Week%20-%206%0A%0A%20%20%20%20Common%20Instructions%0A%0A%20%20%20%20-%20Load%20the%20wine%20dataset%20from%20sklearn.%20%0A%20%20%20%20-%20Split%20the%20dataset%20into%20train%20and%20test%20set%20with%20**70%3A30%20ratio**%20with%20%60random_state%20%3D%201%60%0A%20%20%20%20-%20Use%20this%20for%20all%20the%20questions%20that%20follow%0A%0A%20%20%20%20**Submission%20Date%3A**%20%602025-11-02%2C%2023%3A59%20IST%60%0A%0A%20%20%20%20**Last%20Updated%3A**%20%60%7Bcurr%7D%60%0A%20%20%20%20%22%22%22%0A%20%20%20%20)%0A%20%20%20%20return%20(mo%2C)%0A%0A%0A%40app.cell%0Adef%20_()%3A%0A%20%20%20%20RANDOM_STATE%20%3D%201%0A%20%20%20%20return%20(RANDOM_STATE%2C)%0A%0A%0A%40app.cell%0Adef%20_()%3A%0A%20%20%20%20import%20numpy%20as%20np%0A%20%20%20%20import%20pandas%20as%20pd%0A%20%20%20%20from%20sklearn.datasets%20import%20load_wine%0A%20%20%20%20from%20sklearn.linear_model%20import%20LogisticRegression%0A%20%20%20%20from%20sklearn.model_selection%20import%20train_test_split%2C%20GridSearchCV%0A%20%20%20%20from%20sklearn.metrics%20import%20accuracy_score%0A%20%20%20%20from%20sklearn.tree%20import%20DecisionTreeClassifier%0A%20%20%20%20from%20sklearn.ensemble%20import%20(%0A%20%20%20%20%20%20%20%20AdaBoostClassifier%2C%0A%20%20%20%20%20%20%20%20VotingClassifier%2C%0A%20%20%20%20%20%20%20%20BaggingClassifier%2C%0A%20%20%20%20%20%20%20%20RandomForestClassifier%2C%0A%20%20%20%20%20%20%20%20GradientBoostingClassifier%2C%0A%20%20%20%20)%0A%20%20%20%20return%20(%0A%20%20%20%20%20%20%20%20AdaBoostClassifier%2C%0A%20%20%20%20%20%20%20%20BaggingClassifier%2C%0A%20%20%20%20%20%20%20%20DecisionTreeClassifier%2C%0A%20%20%20%20%20%20%20%20GradientBoostingClassifier%2C%0A%20%20%20%20%20%20%20%20GridSearchCV%2C%0A%20%20%20%20%20%20%20%20LogisticRegression%2C%0A%20%20%20%20%20%20%20%20RandomForestClassifier%2C%0A%20%20%20%20%20%20%20%20VotingClassifier%2C%0A%20%20%20%20%20%20%20%20accuracy_score%2C%0A%20%20%20%20%20%20%20%20load_wine%2C%0A%20%20%20%20%20%20%20%20np%2C%0A%20%20%20%20%20%20%20%20pd%2C%0A%20%20%20%20%20%20%20%20train_test_split%2C%0A%20%20%20%20)%0A%0A%0A%40app.cell%0Adef%20_(load_wine)%3A%0A%20%20%20%20wine_data%20%3D%20load_wine()%0A%0A%20%20%20%20print(wine_data.DESCR)%0A%20%20%20%20return%20(wine_data%2C)%0A%0A%0A%40app.cell%0Adef%20_(pd%2C%20wine_data)%3A%0A%20%20%20%20X%20%3D%20pd.DataFrame(data%3Dwine_data.data%2C%20columns%3Dwine_data.feature_names)%0A%20%20%20%20y%20%3D%20wine_data.target%0A%20%20%20%20return%20X%2C%20y%0A%0A%0A%40app.cell%0Adef%20_(X)%3A%0A%20%20%20%20X.head()%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(X)%3A%0A%20%20%20%20X.info()%0A%20%20%20%20X.describe().T%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(RANDOM_STATE%2C%20X%2C%20train_test_split%2C%20y)%3A%0A%20%20%20%20X_train%2C%20X_test%2C%20y_train%2C%20y_test%20%3D%20train_test_split(%0A%20%20%20%20%20%20%20%20X%2C%20y%2C%20test_size%3D0.3%2C%20random_state%3DRANDOM_STATE%0A%20%20%20%20)%0A%20%20%20%20return%20X_test%2C%20X_train%2C%20y_test%2C%20y_train%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%23%23%20Question%201%20-%202%0A%0A%20%20%20%20Train%20a%20Logistic%20Regression%20model%20with%20the%20following%20parameters%3A%0A%0A%20%20%20%20-%20max_iter%20%3D%2010000%0A%20%20%20%20-%20C%20as%200.5%0A%20%20%20%20-%20random_state%20%3D%201%0A%20%20%20%20-%20solver%20as%20'sag'%0A%0A%20%20%20%20Compute%20the%20accuracy%20on%20the%20test%20data.%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(LogisticRegression%2C%20RANDOM_STATE%2C%20X_train%2C%20y_train)%3A%0A%20%20%20%20lr%20%3D%20LogisticRegression(%0A%20%20%20%20%20%20%20%20max_iter%3D10000%2C%20C%3D0.5%2C%20random_state%3DRANDOM_STATE%2C%20solver%3D%22sag%22%0A%20%20%20%20)%0A%0A%20%20%20%20lr.fit(X_train%2C%20y_train)%0A%20%20%20%20return%20(lr%2C)%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%23%23%23%20Question%201%0A%0A%20%20%20%20What%20is%20the%20accuracy%20of%20the%20model%20on%20the%20test%20data%3F%20%5BEnter%203%20decimal%20places%5D%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(X_test%2C%20accuracy_score%2C%20lr%2C%20np%2C%20y_test)%3A%0A%20%20%20%20_y_pred%20%3D%20lr.predict(X_test)%0A%0A%20%20%20%20np.round(accuracy_score(y_test%2C%20_y_pred)%2C%203)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%23%23%23%20Question%202%0A%0A%20%20%20%20How%20many%20iterations%20did%20the%20algorithm%20take%20to%20converge%3F%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(lr)%3A%0A%20%20%20%20lr.n_iter_.sum()%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%23%23%20Question%203%20-%204%0A%0A%20%20%20%20Perform%20Hyperparameter%20tuning%20on%20a%20decision%20tree%20classifier%20with%20**random_state%20%3D%201**%20and%20**cross%20validation%20%3D%204**.%20The%20Hyperparameter%20tuning%20is%20to%20be%20done%20over%20the%20following%20parameters%3A%0A%0A%20%20%20%20-%20criterion%20can%20be%20'entropy'%20or%20'gini'%0A%20%20%20%20-%20splitter%20can%20be%20'random'%20or%20'best'%0A%20%20%20%20-%20Minimum%20number%20of%20samples%20per%20leaf%20as%20%5B2%2C4%2C6%2C8%2C10%5D%0A%20%20%20%20-%20Maximum%20depth%20as%20%5B3%2C4%2C5%2C6%5D%0A%0A%20%20%20%20Compute%20the%20accuracy%20on%20the%20test%20data.%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_()%3A%0A%20%20%20%20dt_params_dict%20%3D%20%7B%0A%20%20%20%20%20%20%20%20%22criterion%22%3A%20%5B%22entropy%22%2C%20%22gini%22%5D%2C%0A%20%20%20%20%20%20%20%20%22splitter%22%3A%20%5B%22random%22%2C%20%22best%22%5D%2C%0A%20%20%20%20%20%20%20%20%22min_samples_leaf%22%3A%20%5B2%2C%204%2C%206%2C%208%2C%2010%5D%2C%0A%20%20%20%20%20%20%20%20%22max_depth%22%3A%20%5B3%2C%204%2C%205%2C%206%5D%2C%0A%20%20%20%20%7D%0A%20%20%20%20return%20(dt_params_dict%2C)%0A%0A%0A%40app.cell%0Adef%20_(DecisionTreeClassifier%2C%20RANDOM_STATE)%3A%0A%20%20%20%20dtc%20%3D%20DecisionTreeClassifier(random_state%3DRANDOM_STATE)%0A%20%20%20%20return%20(dtc%2C)%0A%0A%0A%40app.cell%0Adef%20_(GridSearchCV%2C%20X_train%2C%20dt_params_dict%2C%20dtc%2C%20y_train)%3A%0A%20%20%20%20dt_grid_search%20%3D%20GridSearchCV(dtc%2C%20param_grid%3Ddt_params_dict%2C%20cv%3D4)%0A%20%20%20%20dt_grid_search.fit(X_train%2C%20y_train)%0A%20%20%20%20return%20(dt_grid_search%2C)%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%23%23%23%20Question%203%0A%0A%20%20%20%20What%20is%20the%20accuracy%20of%20the%20model%20on%20the%20test%20data%3F%20%5BEnter%203%20decimal%20places%5D%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(X_test%2C%20accuracy_score%2C%20dt_grid_search%2C%20np%2C%20y_test)%3A%0A%20%20%20%20_y_pred%20%3D%20dt_grid_search.predict(X_test)%0A%0A%20%20%20%20np.round(accuracy_score(y_test%2C%20_y_pred)%2C%203)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%23%23%23%20Question%204%0A%0A%20%20%20%20What%20is%20the%20value%20of%20best%20max_depth%20after%20training%20with%20GridSearchCV%3F%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(dt_grid_search)%3A%0A%20%20%20%20dt_grid_search.best_params_%5B%22max_depth%22%5D%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%23%23%20Question%205%20-%206%0A%0A%20%20%20%20Perform%20Hyperparameter%20tuning%20on%20an%20adaboost%20classifier%20with%20**random_state%20%3D%201**%20and%20**cross%20validation%20%3D%204**.%20The%20Hyperparameter%20tuning%20is%20to%20be%20done%20over%20the%20following%20parameters%3A%0A%0A%20%20%20%20-%20Number%20of%20estimators%20as%20%5B100%2C%20500%2C%201000%5D%0A%20%20%20%20-%20Learning%20rate%20as%20%5B0.5%2C%201%2C%202%5D%0A%0A%20%20%20%20Compute%20the%20accuracy%20on%20the%20test%20data.%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_()%3A%0A%20%20%20%20ada_params_dict%20%3D%20%7B%0A%20%20%20%20%20%20%20%20%22n_estimators%22%3A%20%5B100%2C%20500%2C%201000%5D%2C%0A%20%20%20%20%20%20%20%20%22learning_rate%22%3A%20%5B0.5%2C%201%2C%202%5D%2C%0A%20%20%20%20%7D%0A%20%20%20%20return%20(ada_params_dict%2C)%0A%0A%0A%40app.cell%0Adef%20_(AdaBoostClassifier%2C%20RANDOM_STATE)%3A%0A%20%20%20%20ada%20%3D%20AdaBoostClassifier(random_state%3DRANDOM_STATE)%0A%20%20%20%20return%20(ada%2C)%0A%0A%0A%40app.cell%0Adef%20_(GridSearchCV%2C%20X_train%2C%20ada%2C%20ada_params_dict%2C%20y_train)%3A%0A%20%20%20%20ada_grid_search%20%3D%20GridSearchCV(estimator%3Dada%2C%20param_grid%3Dada_params_dict%2C%20cv%3D4)%0A%20%20%20%20ada_grid_search.fit(X_train%2C%20y_train)%0A%20%20%20%20return%20(ada_grid_search%2C)%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%23%23%23%20Question%205%0A%0A%20%20%20%20What%20is%20the%20accuracy%20of%20the%20model%20on%20the%20test%20data%3F%20%5BEnter%203%20decimal%20places%5D%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(X_test%2C%20accuracy_score%2C%20ada_grid_search%2C%20np%2C%20y_test)%3A%0A%20%20%20%20_y_pred%20%3D%20ada_grid_search.predict(X_test)%0A%0A%20%20%20%20np.round(accuracy_score(y_test%2C%20_y_pred)%2C%203)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%23%23%23%20Question%206%0A%0A%20%20%20%20What%20is%20the%20value%20of%20best%20n_estimators%20after%20training%20with%20GridSearchCV%3F%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(ada_grid_search)%3A%0A%20%20%20%20ada_grid_search.best_params_%5B%22n_estimators%22%5D%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%23%23%20Question%207%0A%0A%20%20%20%20Train%20a%20voting%20classifier%20by%20making%20use%20of%20the%20following%20estimators%3A%0A%20%20%20%20-%20Bagging%20Classifier%0A%20%20%20%20-%20Random%20Forest%20Classifier%0A%20%20%20%20-%20GradientBoosting%20Classifier%0A%0A%20%20%20%20with%20**random_state%20%3D%201**%20for%20each%20of%20the%20estimators.%0A%0A%20%20%20%20Train%20the%20model%20on%20the%20training%20data%20and%20compute%20the%20score%20on%20the%20test%20data.%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(%0A%20%20%20%20BaggingClassifier%2C%0A%20%20%20%20GradientBoostingClassifier%2C%0A%20%20%20%20RANDOM_STATE%2C%0A%20%20%20%20RandomForestClassifier%2C%0A)%3A%0A%20%20%20%20bc%20%3D%20BaggingClassifier(random_state%3DRANDOM_STATE)%0A%20%20%20%20rf%20%3D%20RandomForestClassifier(random_state%3DRANDOM_STATE)%0A%20%20%20%20gb%20%3D%20GradientBoostingClassifier(random_state%3DRANDOM_STATE)%0A%0A%20%20%20%20models%20%3D%20%5B(%22bagging%22%2C%20bc)%2C%20(%22random_forest%22%2C%20rf)%2C%20(%22gradient_boostig%22%2C%20gb)%5D%0A%20%20%20%20return%20(models%2C)%0A%0A%0A%40app.cell%0Adef%20_(VotingClassifier%2C%20X_train%2C%20models%2C%20y_train)%3A%0A%20%20%20%20voting%20%3D%20VotingClassifier(models)%0A%20%20%20%20voting.fit(X_train%2C%20y_train)%0A%20%20%20%20return%20(voting%2C)%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%23%23%23%20Question%207%0A%0A%20%20%20%20What%20is%20the%20accuracy%20of%20the%20model%20on%20the%20test%20data%3F%20%5BEnter%203%20decimal%20places%5D%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(X_test%2C%20accuracy_score%2C%20np%2C%20voting%2C%20y_test)%3A%0A%20%20%20%20_y_pred%20%3D%20voting.predict(X_test)%0A%0A%20%20%20%20np.round(accuracy_score(y_test%2C%20_y_pred)%2C%203)%0A%20%20%20%20return%0A%0A%0Aif%20__name__%20%3D%3D%20%22__main__%22%3A%0A%20%20%20%20app.run()%0A
14cfa3eca90ef8c239dba0e49f106b013e31ee221e092f0e734ad38bec804335